/**
 * <p>Title: NaviPage.java</p>
 * <p>Description: DoNotes</p>
 * @author WangJun
 * @date 2009/11/25 16:39:20
 * @version 1.0
 */
package net.donotes.util;

import net.donotes.blog.dao.OptionsDao;
import net.donotes.blog.dao.PostDao;

/**
 * @author WangJun
 *
 */
public class NaviPage {
	private int navaPageRange = Constants.PAGE_NAVI_RANGE;;
	private int totalPages = 1;
	
	/**
	 * 
	 */
	public NaviPage() {		
		OptionsDao optionsDao = new OptionsDao();
		this.totalPages = (Integer.parseInt(optionsDao.getOptions(Constants.OPTION_POST_COUNTER))-1)/Constants.PAGE_SIZE + 1;
	}

	/**
	 * 
	 */
	public NaviPage(String category) {
		PostDao postDao = new PostDao();
		this.totalPages = (postDao.getPostsCounter(category) - 1)/Constants.PAGE_SIZE + 1;
	}

	/**
	 * Title: getStartPageNum
	 * @param currentPageNum
	 * @return
	 */
	public int getStartPageNum(int currentPageNum) {
		int startPageNum = currentPageNum - this.navaPageRange;
		
		if (startPageNum < 1) {
			startPageNum = 1;
		}
		return startPageNum;
	}
	
	/**
	 * Title: getEndPageNum
	 * @param currentPageNum
	 * @return
	 */
	public int getEndPageNum(int currentPageNum) {
		int endPageNum = currentPageNum + this.navaPageRange;
		
		if (totalPages < endPageNum) {
			endPageNum = totalPages;
		}
		return endPageNum;
	}
}
